/* 2017-12-4 08:27:25 | 修改 木遥（QQ：516584683） */
//模块：
mars3d.widget.bindClass(mars3d.widget.BaseWidget.extend({
    map: null, //框架会自动对map赋值
    options: {
        //弹窗
        view: {
            type: "window",
            url: "view.html",
            windowOptions: {
                width: 270,
                height: 500,
                "position": {
                    "top": 70,
                    "bottom": 40,
                    "left": 15
                }
            }
        }
    },
    //初始化[仅执行1次]
    create: function() {


    },
    viewWindow: null,

    //每个窗口创建完成后调用
    winCreateOK: function(opt, result) {
        this.viewWindow = result;
    },
    //打开激活
    activate: function() {


    },
    //关闭释放
    disable: function() {
        this.viewWindow = null;
        this.resetStyle();
    },
    getTreeUrl: function() {
        var url = this.config.layerWork.config.url;
        url = url.substring(0, url.lastIndexOf('/') + 1) + this.config.scenetree;

        var that = this;
        $.ajax({
            url: url,
            dataType: 'json',
            success: function(scene) {
                that.viewWindow.initSceneTree(scene);
            }
        });
    },
    resetStyle: function() {
        var tileset = this.config.layerWork.model;

        tileset.style = undefined;
    },
    //清除tip
    hideTooltip: function() {
        viewer.mars.popup.close();
    },
    //定位
    locateNode: function(nodeid, nodesphere) {
        if (nodesphere[3] <= 0)
            return;

        var tileset = this.config.layerWork.model;
        var orginMatrixInverse = this.config.layerWork.orginMatrixInverse;

        //飞行过去 
        var center = new Cesium.Cartesian3(nodesphere[0], nodesphere[1], nodesphere[2]);

        if (orginMatrixInverse && tileset._root.transform) {
            var mat = Cesium.Matrix4.multiply(tileset._root.transform, orginMatrixInverse, new Cesium.Matrix4());
            center = Cesium.Matrix4.multiplyByPoint(mat, center, new Cesium.Cartesian3());
        }

        var sphere = new Cesium.BoundingSphere(center, nodesphere[3]);
        this.viewer.camera.flyToBoundingSphere(sphere, {
            duration: 0.5
        });

        //设置tileset的样式 
        tileset.style = new Cesium.Cesium3DTileStyle({
            color: {
                conditions: [
                    ["${id} ==='" + nodeid + "'", "rgb(255, 255, 255)"],
                    ["true", "rgba(255, 200, 200,0.2)"]
                ]
            }
        });

    },




}));